import {
	login
} from '@/api/index.js';

const wxLogin = function(callback) {
	const existToken = uni.getStorageSync("token");
	if (!existToken) {
		uni.login({
			success(res) {
				const code = res.code;
				login({
					jsCode: code,
				}).then(res => {
					debugger;
					const {
						token,
						avatarUrl,
						nickName,
						secret
					} = res.data;
					uni.setStorageSync('token', token);
					uni.setStorageSync('secret', secret);
					uni.setStorageSync("userInfo", JSON.stringify({
						avatarUrl,
						nickName
					}))
					callback({
						avatarUrl,
						nickName
					})
				});
			}
		});
	}
}
export {
	wxLogin
}
